package org.advanced.expand;

import java.util.ArrayList;
import java.util.List;

/**
 * @author John.zhang
 * @version Id: Allocator, v 1.0 2020/12/11 17:28 ZhiYong Exp $
 */
public class Allocator {

    private List<Object> list = new ArrayList<>();

    synchronized boolean apply(Object from, Object to) {
        if (list.contains(from) || list.contains(to)) {
            return false;
        } else {
            list.add(from);
            list.add(to);
            return true;
        }
    }

    synchronized void free(Object from, Object to) {
        list.remove(from);
        list.remove(to);
    }
}
